from core.data.student_data_access import save_students,loads_students_json

# 学生信息字典
# students = {
#     # "1001": {"user": "yuan", "pwd": "123"}
# }
students = loads_students_json()

def reg():
    stu_id = input("请输入学生的学号")
    if stu_id in students:
        return False, students[stu_id]["user"]
    user = input("请输入学生的姓名")
    pwd = input("请输入学生的密码")
    students[stu_id] = {"user": user, "pwd": pwd}
    save_students(students)
    return True, user

def login():
    global is_login
    global student_id
    stu_id = input("请输入学生学号:")
    if stu_id in students:
        # 获取用户名和密码，然后比对认证
        stu_pwd = input("请输入学生密码：")
        if stu_pwd == students[stu_id]["pwd"]:
            print(f"欢迎回来，{students[stu_id]['user']}")

            return stu_id
        else:
            # print("账号或密码错误！")
            return 401
    else:
        # print(f"{stu_id}学号不存在，请先注册")
        return 402

